import Int from "../type/Q/int"

/**
 * 
 * @param {BigInt} value 
 */
export default function getFractor(value) {
    if (value in Int.fractors)
        return Int.fractors[value.toString()]
    if(!value instanceof BigInt) 
        throw new TypeError("value must be an BigInt")
    if (value <= 0n)
        throw new RangeError("value must be a positive Int")
    /**
     * @type {BigInt[]}
     */
    let fractors = []
    for (let i = 1n; i <= value / 2n; i += 1n) {
        if (value % i === 0n) 
            fractors.push(i, value / i)
    }
    fractors = [...new Set(fractors)]
    Int.setFractor(value.toString(), fractors)
    return fractors;
}